
 <template>
  <div class="lunbo">
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white" @change="changeIndex" :initial-swipe="startIndex">
      <van-swipe-item v-for="(item, index) in data.imgs" :key="index" @click="previewImg(index)">
        <img :src="item" alt="商品图片" style="width: 100%; height: 80%; object-fit: cover;">
      </van-swipe-item>
      <template #indicator="{active,total}">
       <div class="custom-indicator"> {{ active + 1 }}/{{ total }}</div>
       
      </template>
      
    </van-swipe>
  </div>
</template>


<script>
// import { showImagePreview } from 'vant';
// import { preview } from 'vite';



export default {
  props: ["data"],
 data(){
     return{
          startIndex:0
  }
 },
 methods:{
  previewImg(index){
    showImagePreview({
      images:this.data.imgs,
      startPosition:index,
      swipeDuration:2000,
      onChange:(idx)=>{
        console.log("idx",idx);
        this.startIndex=idx

      }
    })
  },
    changeIndex(index){
        this.startIndex=index;
    }
 }
};
</script>

<style scoped>
  .my-swipe .van-swipe-item {
    color: #fff;
    font-size: 20px;
    line-height: 150px;
    text-align: center;
    background-color: #39a9ed;
  }
  .custom-indicator {
    position: absolute;
    right: 5px;
    bottom: 5px;
    padding: 2px 5px;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.1);
}

  </style>
